package paket;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import com.google.appengine.labs.repackaged.org.json.JSONArray;
import sesion.AdministratorDaoJpa;
import sesion.ProizvodDaoJpa;

@SuppressWarnings("serial")
public class ProdavnicaServlet extends HttpServlet {
	private ProizvodDaoJpa proizvodDaoJpa=new ProizvodDaoJpa();
	private AdministratorDaoJpa administratorDaoJpa=new AdministratorDaoJpa();
	private boolean registrovao=false;
	public void doGet(HttpServletRequest req, HttpServletResponse resp)throws IOException, ServletException 
	{
		/*Korisnik korisnik=new Administrator("admin", "123", "BG");
		korisnikDaoJpa.save(korisnik);*/
		//proizvodDaoJpa.findAll();
		if(registrovao==false)
		{
			administratorDaoJpa.registrujAdmina("admin", "123", "bla");
			registrovao=true;
		}
		JSONArray objekti=proizvodDaoJpa.vratiJsonProizvode();
		req.setAttribute("proizvodnaPomagala",objekti);
		RequestDispatcher disp = req.getRequestDispatcher("./prodavnica.jsp");
		disp.forward(req, resp);
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException 
	{
		doGet(request, response);
	}
}
